import { Component } from 'react'
import { AtNoticebar } from 'taro-ui'
import { View } from '@tarojs/components'
import Taro from "@tarojs/taro"

import "taro-ui/dist/style/components/noticebar.scss";
import "taro-ui/dist/style/components/icon.scss";
import "taro-ui/dist/style/components/button.scss";


export default class CustomNotice extends Component{

    constructor(){
        super(...arguments)
        this.state = {
            // noticeContent内容设为动态的，可以后端手动修改的。
            noticeContent: '紧急通知：快退后，我要开始装逼了！'
        }
    }

    /**
     * 组件将要渲染时，加载出通告栏目的信息。
     */
    async componentWillMount(){
        try{
            const res = await Taro.request({
                // url: '/api/v1/freerdbj/fwtm/aoam/acceptorderback/query/1', //仅为示例，并非真实的接口地址
                url: 'http://10.161.128.18:2779/freerdbj/fwtm/aoam/acceptorderback/query/1',
                data: {
                    // x: '',
                    // y: ''
                },
                header: {
                    'content-type': 'application/json' // 默认值
                },
                method: "GET"
            })
            this.setState({
                noticeContent: res.data.MSG
            });
        }catch{
            Taro.showToast({
                title: "载入远程数据错误"
            })
        }
    }

    render(){
        const { noticeContent } = this.state;
        return(
            <View>
                <AtNoticebar 
                    icon='volume-plus' 
                    marquee
                    close={true}
                    speed={200}
                    onClose={() => {}}
                    >
                    {noticeContent}
                </AtNoticebar>
            </View>
        )
    }
}